package com.xmy.cultivate.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xmy.cultivate.entity.AuditClaim;
import com.xmy.cultivate.entity.AuditFlow;
import com.xmy.cultivate.entity.Department;
import com.xmy.cultivate.entity.StudentAccount;
import com.xmy.cultivate.respons.FlowRs;
import com.xmy.cultivate.service.IAuditClaimService;
import com.xmy.cultivate.service.IAuditFlowDetailService;
import com.xmy.cultivate.service.IAuditFlowService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.IdWorker;
import com.xmy.cultivate.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 实例审核流程详情 前端控制器
 * </p>
 *
 * @author hpiggy
 * @since 2025-01-01
 */
@RestController
@RequestMapping("/api/auditFlow")
@Scope("prototype")
public class AuditFlowController extends BaseController {
    @Autowired
    IAuditFlowService iAuditFlowService;

    @Autowired
    IAuditFlowDetailService iAuditFlowDetailService;

    @Autowired
    IdWorker idWorker;

    @Autowired
    IAuditClaimService iAuditClaimService;

    @GetMapping("")
    @ApiOperation("获取审核类型")
    public Result getDepartment() {

        QueryWrapper<AuditFlow> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1);
        List<AuditFlow> flowRsList = iAuditFlowService.list(queryWrapper);

        return new Result(Code.OK, flowRsList, Code.GET_OK_MSG);
    }


    @GetMapping("/getFlowTask")
    @ApiOperation("获取审批流程")
    public List<FlowRs> getFlowTask(@RequestParam(value = "flowId", required = false, defaultValue = "") Long flowId,// 流程id
                              @RequestParam(value = "schoolId", required = false, defaultValue = "") Long schoolId,// 校区id
                              @RequestParam(value = "departId", required = false, defaultValue = "") Long departId // 部门id
    ) {

        List<FlowRs> flowRsList = iAuditFlowService.getFlowTask(flowId, schoolId, departId, this.adminId);
        return flowRsList;
    }

    @PostMapping("/addFlowTask")
    @ApiOperation("添加实例流程")
    public void addFlowTask(@RequestBody AuditClaim auditClaim) {
        iAuditFlowService.addFlowTask(auditClaim.getId(), auditClaim.getFlowId(), auditClaim.getSchoolId(), null, auditClaim.getCreatedId());
        iAuditFlowDetailService.sendRemind(auditClaim.getId(),auditClaim.getStepNum());
    }

    @PostMapping("/addFlowTaskOut")
    @ApiOperation("添加实例流程对外调用")
    public void addFlowTaskOut(@RequestBody AuditClaim auditClaim) {
        iAuditFlowService.addFlowTask(auditClaim.getId(), auditClaim.getFlowId(), auditClaim.getSchoolId(), null, auditClaim.getCreatedId());
        AuditClaim auditClaimNew = iAuditClaimService.getById(auditClaim.getId());
        iAuditFlowDetailService.sendRemind(auditClaim.getId(),auditClaimNew.getStepNum());
    }

}
